{% extends '../_manage.html' %}

{% block title %} {{ form.name }} {% endblock %}

{% block head %}

<script>
$(function() {
    var id = parseInt('{{ id }}');
    if (id > 0) {
        getJSON('/api/boards/' + id, function (err, resp) {
            if (err) {
                return showError(err);
            }
            initVM({
	        	title: 'Edit Board',
        		board: resp
        	});
        });
    }
    else {
        initVM({
        	title: 'New Board',
        	board: {}
        });
    }
});

function initVM(data) {
    var vm = new Vue({
        el: '#vm',
        data: {
            title: data.title,
            board: data.board
        },
        created: function () {
            $('#loading').hide();
            $('#vm').show();
        },
        methods: {
            submit: function() {
                var that = this;
                that.$resource('{{ action }}').save(this.board).then(function (resp) {
                    resp.json().then(function (result) {
                        location.assign('/manage/board/');
                    });
                }, onJsonFormError);
            }
        }
    });
}
</script>

{% endblock %}

{% block main %}

    <div id="loading" class="uk-width-1-1">
        <i class="uk-icon-spinner uk-icon-spin"></i> {{ _('Loading') }}...
    </div>

    <div id="vm" class="uk-width-1-1">
        <ul class="uk-tab" data-uk-tab>
            <li class="uk-active"><a href="#0">{{ _('Boards') }}</a></li>
            <li class="uk-disabled"><a href="#0">{{ _('Topics') }}</a></li>
            <li class="uk-disabled"><a href="#0">{{ _('Replies') }}</a></li>
        </ul>

        <form v-on:submit.prevent="submit" class="uk-margin uk-form uk-form-stacked">
            <legend v-text="title"></legend>
            <fieldset>
                <div class="uk-alert uk-alert-danger uk-hidden"></div>
                <div class="uk-form-row">
                    <label class="uk-form-label">{{ _('Name') }}:</label>
                    <div class="uk-form-controls">
                        <input v-model="board.name" name="name" type="text" maxlength="100" class="uk-width-1-1">
                    </div>
                </div>
                <div class="uk-form-row">
                    <label class="uk-form-label">{{ _('Tag') }}:</label>
                    <div class="uk-form-controls">
                        <input v-model="board.tag" name="tag" type="text" maxlength="50" class="uk-width-1-1">
                    </div>
                </div>
                <div class="uk-form-row">
                    <label class="uk-form-label">{{ _('Description') }}:</label>
                    <div class="uk-form-controls">
                        <input v-model="board.description" name="description" type="text" maxlength="100" class="uk-width-1-1">
                    </div>
                </div>
                <div class="uk-form-row">
                    <div class="uk-form-controls">
                        <button type="submit" class="uk-button uk-button-primary"><i class="uk-icon-check"></i> {{ _('Save') }}</button>
                        <button type="button" class="uk-button" onclick="location.assign('/manage/board/')"><i class="uk-icon-times"></i> {{ _('Cancel') }}</button>
                    </div>
                </div>
            </fieldset>
        </form>
    </div>

{% endblock %}
